<template>
    <div>
        <van-nav-bar
                :fixed="true"
                @click-left="onClickLeft"
        >
            <div class="van-nav-bar_title" slot="title">{{ $t('helpCenter.title') }}</div>
            <van-icon name="arrow-left" slot="left" class="nav_bar_icon"></van-icon>
        </van-nav-bar>
        <van-row  class="main">
            <van-overlay :show="loading"></van-overlay>
            <van-loading v-if="loading" type="spinner" class="loading"  vertical></van-loading>
            <van-row v-else>
                <van-row class="btnGroup">
                    <van-col span="12">
                        <div class="btn" @click="phone">{{$t('helpCenter.phone')}}</div>
                    </van-col>
                    <van-col span="12">
                        <div class="btn" @click="feedBack">{{$t('helpCenter.feedback')}}</div>
                    </van-col>
                </van-row>
                <van-panel v-for="(item,index) of helpData" :key="index">
                    <div slot="header" class="text-item">
                        <van-row>
                            <van-col span="24" class="textCenter">
                                {{item['title']}}
                            </van-col>
<!--                            <van-col span="6" class="rightIcon">-->
<!--                                <van-col span="12" @click="good(item)">-->
<!--                                    <van-icon class="icon" name="like-o" :class="item['usefulEnum']==='USEFUL' ? 'active' : ''" />-->
<!--                                    <div class="rightIconText">{{$t('helpCenter.itWorks')}}</div>-->
<!--                                </van-col>-->
<!--                                <van-col span="12" @click="bad(item)">-->
<!--                                    <van-icon class="icon" name="like-o" :class="item['usefulEnum']==='USELESS' ? 'active' : ''" />-->
<!--                                    <div class="rightIconText">{{$t('helpCenter.useless')}}</div>-->
<!--                                </van-col>-->
<!--                            </van-col>-->
                        </van-row>
                        <van-divider class="divider"></van-divider>
                        <div class="text">{{item['contents']}}</div>
                    </div>
                </van-panel>
            </van-row>

        </van-row>
    </div>
</template>

<script>
import {helpCenter, helpCenterChose} from '@/api/index'
    export default {
        name: "help-center",
        data(){
            return{
                helpData:[],
                loading:true
            }
        },
        mounted(){
            this.getInfo();
        },
        methods:{
            onClickLeft(){
                this.$bridge.goBack();
            },
            getData(){
                helpCenter().then(res => {
                    this.loading=false;
                    if (res.data.success) {
                        this.helpData = res.data.data;
                    } else {
                        this.$notify(res.data.message);
                    }
                })
            },
            phone(){
                this.$bridge.getCall();
            },
            feedBack(){
                this.$router.push({
                    name:"feed-back"
                })
            },
            good(data){
                this.loading=true;
                let str=data['usefulEnum']==='USEFUL' ? 'NOT_SELECT' : 'USEFUL';
                let params={
                    helpId:data['id'],
                    usefulEnum:str
                };
                helpCenterChose(params).then(res => {
                    if (res.data.success) {
                        this.getData();
                    } else {
                        this.$notify(res.data.message);
                    }
                })
            },
            bad(data){
                this.loading=true;
                let str=data['usefulEnum']==='USELESS' ? 'NOT_SELECT' : 'USELESS';
                let params={
                    helpId:data['id'],
                    usefulEnum:str
                };
                helpCenterChose(params).then(res => {
                    if (res.data.success) {
                        this.getData();
                    } else {
                        this.$notify(res.data.message);
                    }
                })
            },
            getInfo(){
                this.take().then(data => {
                    console.log("回调", data);
                    if(data){
                        window.sessionStorage.setItem("loginInfo", JSON.stringify(data));
                        this.getData();
                    }else{
                        this.$bridge.goLogin()
                    }
                });
            },
            take(){
                return new Promise((resolve,reject)=>{
                    this.$bridge["getLoginInfo"](null, res => {
                        resolve(JSON.parse(res));
                    });
                });
            },
        }
    }
</script>

<style scoped lang="less">
    @import "../assets/css/main";
    .btnGroup{
        text-align: center;
        padding: 16px 0;
        .btn{
            margin: 0 auto;
            width: 90%;
            background-color: #39C581;
            color: #FFFFFF;
            height: 44px;
            line-height: 44px;
            font-size: 15px;
            border:1PX solid #39C581;
            border-radius: 4px;
        }
    }
    .text-item{
        background-color: #ffffff;
        padding: 8px 16px;
        .textCenter{
            font-size: 16px;
            font-weight: 400;
            color: #2D3632;
            line-height: 24px;
        }
        .rightIcon{
            text-align: center;
            .icon{
                font-size: 18px;
                color: #E0E0E0;
            }
            .active{
                color: #39C581;
            }
            .rightIconText{
                width: 100%;
                font-size: 12px;
                color: #2D3632;
                line-height: 18px;
            }
        }
        .text{
            padding: 16px;
            color: #2D3632;
            font-size: 14px;
            font-weight: 400;
            line-height: 20px;
        }
    }
    .divider{
        margin: 0;
    }
    .loading{
        z-index: 1000;
        position: absolute;
        margin-top: 60%;
        margin-left: 45%;
    }
</style>